package com.itqianfeng.smartmeeting.controller;


import com.itqianfeng.smartmeeting.entity.Timeslot;
import com.itqianfeng.smartmeeting.service.TimeslotService;
import com.itqianfeng.smartmeeting.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/timeslot")
public class TimeslotController {
    @Autowired
    private TimeslotService timeslotService;
    @GetMapping("/list")
    public Map list(int page ,int limit,Integer roomId){
    try{
        List<Timeslot> list = timeslotService.findByRoomId(roomId, (page - 1)*limit, limit);
        return CommonResult.ok("查询成功",list);
    }catch (Exception e){
        e.printStackTrace();
        return CommonResult.error("发生异常",-1);
    }
    }
    @PutMapping("/update")
    public Map update(Timeslot timeslot){
        try{
            boolean flag = timeslotService.updateById(timeslot);
            return CommonResult.ok(flag?"修改成功":"修改失败", null);}
        catch (Exception e){
            return CommonResult.error("发生异常",-1);
        }
    }


}
